package com.meritdata.cloud.data.standard.table.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.meritdata.cloud.data.base.ResultData;
import com.meritdata.cloud.data.standard.table.service.IDictModelService;
import com.meritdata.cloud.utils.SessionUtils;

@RestController
@RequestMapping("/dict/table")
public class DictModelController {

	@Autowired
	private IDictModelService dictModelService;

	@Autowired
	private SessionUtils sessionUtils;

	@RequestMapping("/page")
	public ResultData page(HttpServletRequest request, @RequestParam Long dirId, @RequestParam int pageNum,
			@RequestParam int pageSize, @RequestParam(required=false) String name) {
		ResultData result = new ResultData();
		result.setData(dictModelService.page(dirId, pageNum, pageSize, name));
		return result;
	}

	@RequestMapping("/get")
	public ResultData get(HttpServletRequest request, @RequestParam long id) {
		ResultData result = new ResultData();
		result.setData(dictModelService.get(id));
		return result;
	}

	@RequestMapping("/create")
	public ResultData create(HttpServletRequest request, @RequestParam String name, @RequestParam String code,
			@RequestParam(required=false) String description, @RequestParam Long dirId) {
		return dictModelService.create(name, code, description, dirId, sessionUtils.getCurrentUserId());
	}

	@RequestMapping("/delete")
	public ResultData delete(HttpServletRequest request, @RequestParam long id) {
		return dictModelService.delete(id);
	}

	@RequestMapping("/update")
	public ResultData update(HttpServletRequest request, @RequestParam String name, @RequestParam String code,
			@RequestParam(required=false) String description, @RequestParam long id) {
		return dictModelService.update(name, code, description, id, sessionUtils.getCurrentUserId());
	}

	@RequestMapping("/enable")
	public ResultData enable(HttpServletRequest request, @RequestParam int status, @RequestParam long id) {
		return dictModelService.enable(id, status);
	}

}
